layui.extend({
    baseConfig : "/js/pages/baseConfig"
})
layui.use(['form','layer','laydate','table','laytpl','element','util','baseConfig'],function(){

    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        baseConfig = layui.baseConfig,
        $ = layui.jquery;

    var type = getUrlParamer( "type");
    var adminUserId = getUrlParamer( "adminUserId");

    //绑定校验
    form.verify({
        bankNo : function(val){
            if( !val || val == ''){
                return "卡号为必填";
            }
        }
    });

    //监听提交
    form.on("submit(submitBtn)",function( data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        if( type == 1){
            //提交数据
            $.post( "/mooncardCard/addOrUpdate",{
                bankNo : data.field.bankNo,
                adminUserId : adminUserId
            },function( res){
                if( res.code == 200){
                    setTimeout(function(){
                        top.layer.close( index);
                        top.layer.alert( res.msg);
                        layer.closeAll( "iframe");
                        //刷新父页面
                        parent.location.reload();
                    },500);
                }else if( res.code == 60002){
                    top.layer.close( index);
                    top.layer.msg( res.msg);
                }else if( res.code == 60001){
                    top.layer.close( index);
                    top.layer.msg( res.msg);
                }
            });
        }else{
            //提交数据
            $.post( "/mooncardCard/delByBankNo",{
                bankNo : data.field.bankNo
            },function( res){
                if( res.code == 200){
                    setTimeout(function(){
                        top.layer.close( index);
                        top.layer.alert( res.msg);
                        layer.closeAll( "iframe");
                        //刷新父页面
                        parent.location.reload();
                    },500);
                }else if( res.code == 60001){
                    top.layer.close( index);
                    top.layer.msg( res.msg);
                }
            });
        }

    });
});
